package com.bw.zhuangao5___day002.Fragment;


import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ToastUtils;
import com.bw.mvp.V.BannerFragment;
import com.bw.zhuangao5___day002.Activity.MainActivity;
import com.bw.zhuangao5___day002.Fragment.Books.BaseLinearMannager;
import com.bw.zhuangao5___day002.Fragment.Books.JavaList;
import com.bw.zhuangao5___day002.Fragment.Books.LinearLayoutBooks;
import com.bw.zhuangao5___day002.Fragment.Books.ListBooks;
import com.bw.zhuangao5___day002.R;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.umeng.commonsdk.utils.UMUtils;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMAuthListener;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMWeb;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class BlankFragmentBooks extends BannerFragment {


    private StandardGSYVideoPlayer booksGSYV;
    private RecyclerView booksView;




    @Override
    public int bandLayoud() {
        return R.layout.fragment_blank_fragment_books;
    }

    @Override
    public void initView() {

        booksView = (RecyclerView) findViewById(R.id.books_view);
        booksView.setLayoutManager(new LinearLayoutBooks(getActivity()));

    }

    @Override
    public void initDate() {

        List<JavaList> javaLists = new ArrayList<>();

        for (int i = 0; i < ListBooks.lister.length; i++) {
            javaLists.add(new JavaList());
        }

        BaseLinearMannager mannager = new BaseLinearMannager(javaLists);
        booksView.setAdapter(mannager);

        booksView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                switch (newState)
                {
                    case RecyclerView.SCROLL_STATE_IDLE:
                        RecyclerView.LayoutManager layoutManager = booksView.getLayoutManager();
                        booksGSYV = layoutManager.getChildAt(0).findViewById(R.id.gsyvyang);
                        //视频返回按键监听
                        booksGSYV.getBackButton().setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                MainActivity.fanhui();//返回键回到我的信息
                            }
                        });
                        ImageView touxiang = booksGSYV.findViewById(R.id.touxiang);
                        touxiang.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ToastUtils.showShort("偷袭");
                            }
                        });
                        ImageView fenxiang = booksGSYV.findViewById(R.id.fenxiang);
                        fenxiang.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                UMShareAPI umShareAPI=UMShareAPI.get(getActivity());
                                umShareAPI.getPlatformInfo(getActivity(), SHARE_MEDIA.QQ, new UMAuthListener() {
                                    @Override
                                    public void onStart(SHARE_MEDIA share_media) {

                                    }

                                    @Override
                                    public void onComplete(SHARE_MEDIA share_media, int i, Map<String, String> map) {

                                    }

                                    @Override
                                    public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {

                                    }

                                    @Override
                                    public void onCancel(SHARE_MEDIA share_media, int i) {

                                    }
                                });
                                /*  ToastUtils.showShort("分享······");
                                new ShareAction(getActivity()).withMedia(new UMWeb("https://img.alicdn.com/tfs/TB1dLGBe8Cw3KVjSZR0XXbcUpXa-200-80.png")).withText("hello").setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ,SHARE_MEDIA.WEIXIN)
                                        .setCallback(new UMShareListener() {
                                            @Override
                                            public void onStart(SHARE_MEDIA share_media) {

                                            }

                                            @Override
                                            public void onResult(SHARE_MEDIA share_media) {

                                            }

                                            @Override
                                            public void onError(SHARE_MEDIA share_media, Throwable throwable) {

                                            }

                                            @Override
                                            public void onCancel(SHARE_MEDIA share_media) {

                                            }
                                        }).open();*/

                            }
                        });
                        ImageView pinglun = booksGSYV.findViewById(R.id.pinglun);
                        pinglun.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ToastUtils.showShort("评论");
                            }
                        });

                        ImageView liwule = booksGSYV.findViewById(R.id.liwule);
                        liwule.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ToastUtils.showShort("礼物系统");
                            }
                        });

                        //视频全屏按键监听
                        booksGSYV.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                booksGSYV.setNeedLockFull(true);//是否需要全屏锁定屏幕功能  如果单独使用请设置setIfCurrentIsFullscreen为true
                                booksGSYV.setIfCurrentIsFullscreen(true);
                                booksGSYV.startWindowFullscreen(getActivity(), true, true);
                            }
                        });

                    booksGSYV.startPlayLogic();//开始播放的
                        break;
                }
            }
        });




    }


    //视频播放生命周期
    @Override
    public void onPause() {
        super.onPause();
        GSYVideoManager.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        GSYVideoManager.onResume(true);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        GSYVideoManager.releaseAllVideos();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(getActivity()).onActivityResult(requestCode, resultCode, data);
    }
}
